package cn.com.freelibra.forum.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.quartz.Job;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.com.freelibra.forum.dao.JobSettingMapper;
import cn.com.freelibra.forum.po.JobSetting;
import cn.com.freelibra.forum.po.JobSettingExample;
import cn.com.freelibra.forum.service.JobSettingService;

@Service("jobSettingService")
public class JobSettingServiceImpl implements JobSettingService{

	@Resource
	JobSettingMapper dao;
	
	@Override
	public Page<Map<String, Object>> selectJobSettingList(String keyword, Integer pageNumber, Integer pageSize) {
		pageNumber = pageNumber == null?1:pageNumber;
		pageSize = pageSize == null?5:pageSize;
		PageHelper.startPage(pageNumber,pageSize);
		keyword = (keyword==null||"".equals(keyword.trim()))?null:("%"+keyword+"%");
		Page<Map<String, Object>>  map = dao.selectJobSetting(keyword);
		return map;
	}

	@Override
	public int saveSetting(JobSetting jobSetting) {
		// TODO Auto-generated method stub
		return dao.insert(jobSetting);
	}

	
	public List<JobSetting> getAllSetting() {
		// TODO Auto-generated method stub
		return dao.selectAll();
	}

	@Override
	public List<JobSetting> byStatus(Integer loadRunning) {
		// TODO Auto-generated method stub
		JobSettingExample jobSettingExample = new JobSettingExample();
		jobSettingExample.createCriteria().andRunningStatusEqualTo(loadRunning);
		return dao.selectByEntity(jobSettingExample);
	}

	@Override
	public JobSetting load(Integer id) {
		// TODO Auto-generated method stub
		JobSettingExample jobSettingExample = new JobSettingExample();
		jobSettingExample.createCriteria().andIdEqualTo(id);
		return (JobSetting)dao.selectByEntity(jobSettingExample).get(0);
	}

	@Override
	public void updateJobSetting(JobSetting jobSetting) {
		dao.updateJobSetting(jobSetting);
	}

	@Override
	public boolean deleteJobSetting(JobSetting jobSetting) {
		// TODO Auto-generated method stub
		if(dao.delete(jobSetting)>0){
			return true;
		}else{
			return false;
		}
	}

}
